import time
from datetime import timedelta
from flask import Flask
from flask import request, make_response
from flask import session as sess

app = Flask(__name__)
app.secret_key = "qiku"
# app.config["SESSION_SO"]


@app.route("/")
def index():
    return "<h1>我是首页</h1>"


@app.route("/cookie/")
def cookie():
    time0 = request.cookies.get("time0")

    # 在响应 设置cookie
    res = make_response("<h1>我是cookie</h1>")
    res.set_cookie("time0", str(time.time()), max_age=timedelta(days=7))
    return res

    # res = make_response("<h1>我是cookie</h1>")
    # res.set_cookie("time0", str(time.time()), expires=0)
    # return res


@app.route("/session/")
def session():
    for k, v in sess.items():
        print(f"session:{k}, {v}")

    sess["name"] = "qiku"
    sess["age"] = 20
    sess["time0"] = str(time.time())

    sess.clear()
    return "<h1>我是session</h1>"


def main():
    app.run(debug=True)


if __name__ == '__main__':
    main()
